package com.example.dubbo.order.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.dubbo.dto.OrderDto;
import com.example.dubbo.order.entity.Order;
import com.example.dubbo.order.entity.OrderDetail;
import com.example.dubbo.order.mapper.OrderMapper;
import com.example.dubbo.service.OrderService;
import com.example.dubbo.vo.OrderInfoVo;
import lombok.AllArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zxs
 * @since 2021/9/17
 */
@DubboService
@Service
@AllArgsConstructor
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    private final OrderDetailServiceImpl orderDetailService;

    @Transactional
    @Override
    public Long create(OrderDto dto) {
        Order o = new Order();
        BeanUtil.copyProperties(dto,o);
        this.save(o);
        OrderDetail od = new OrderDetail();
        od.setOrderId(o.getId());
        od.setContent("订单明细");
        od.setOrderType(o.getOrderType());
        orderDetailService.save(od);
        return o.getId();
    }

    public OrderInfoVo getDetail(Long orderId, String orderType){
        return this.baseMapper.getDetail(orderId,orderType);
    }
}
